﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZLCMS.Business.DwzFrame;
using NHibernate;
using ZLCMS.Data.Model;
using ZLCMS.Business;
namespace ZLCMS.Web.SystemManage.Basics.Operator
{
    public partial class Delete : System.Web.UI.Page
    {
        private FrameHelper _framePage;

        protected void Page_Load(object sender, EventArgs e)
        {
            _framePage = new FrameHelper(this);

            using (ISession session = DotNet.Common.NHibernateUtil.SessionFactoryHelper.CreateSession())
            {
                if (Request["mult"] == "1")
                {
                    String ids = Request["ids"];

                    if (!String.IsNullOrEmpty(ids))
                    {
                        String[] idArray = ids.Split(',');
                        foreach (String id in idArray)
                        {
                            Opt(Request["opt"], int.Parse(id), session);
                        }
                    }
                }
                else if (!String.IsNullOrEmpty(Request["uid"]))
                {
                    Opt(Request["opt"], int.Parse(Request["uid"]), session);
                }
                else
                {
                    _framePage.Alert(new ReturnCode() { statusCode = 300, message = "操作失败-参数错误!" });
                }

                session.Flush();
            }

            _framePage.Alert(new ReturnCode() { statusCode = 200, message = "操作成功!", navTabId = _framePage.NavTabId });
        }


        private void Opt(string opt, int id, ISession session)
        {
            switch (opt)
            {
                case "del": OptDelete(id, session); break;
                default: break;
            }
        }

        private void OptDelete(int id, ISession session)
        {
            try
            {
                session.Delete(new UserInfo() { Id = id });
                session.Flush();
            }
            catch (System.Exception ex)
            {

                _framePage.Alert(new ReturnCode() { statusCode = 300, message = "操作失败-" + ex.Message });
                return;
            }

        }
    }
}
